package com.yml.ktbus.core

import android.content.Context
import com.yml.ktbus.core.LiveEventBusCore.Companion.get
import com.yml.ktbus.logger.Logger
import com.yml.ktbus.utils.AppUtils.Companion.init

/**
 * Created by liaohailiang on 2019-08-28.
 */
class Config {
    /**
     * lifecycleObserverAlwaysActive
     * set if then observer can always receive message
     * true: observer can always receive message
     * false: observer can only receive message when resumed
     *
     * @param active boolean
     * @return Config
     */
    fun lifecycleObserverAlwaysActive(active: Boolean): Config {
        get().setLifecycleObserverAlwaysActive(active)
        return this
    }

    /**
     * @param clear boolean
     * @return true: clear livedata when no observer observe it
     * false: not clear livedata unless app was killed
     */
    fun autoClear(clear: Boolean): Config {
        get().setAutoClear(clear)
        return this
    }

    /**
     * config broadcast
     * only if you called this method, you can use broadcastValue() to send broadcast message
     *
     * @param context Context
     * @return Config
     */
    fun setContext(context: Context?): Config {
        init(context)
        return this
    }

    /**
     * setLogger, if not set, use DefaultLogger
     *
     * @param logger Logger
     * @return Config
     */
    fun setLogger(logger: Logger?): Config {
        get().setLogger(logger!!)
        return this
    }

    /**
     * set logger enable or disable, default enable
     *
     * @param enable boolean
     * @return Config
     */
    fun enableLogger(enable: Boolean): Config {
        get().enableLogger(enable)
        return this
    }
}